//
//  RegisterView.m
//  豆瓣
//
//  Created by dllo on 15/12/8.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "RegisterView.h"

@interface RegisterView ()<UITextFieldDelegate>


@property (retain, nonatomic) UILabel *accountLabel;
@property (retain, nonatomic) UILabel *codeLabel;
@property (retain, nonatomic) UILabel *isCodeLabel;
@property (retain, nonatomic) UILabel *teleLabel;
@property (retain, nonatomic) UILabel *mailLabel;

@property (copy, nonatomic) NSString *temp;
@property (copy, nonatomic) NSString *passwordTemp;

@end

@implementation RegisterView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/



- (void)dealloc{
    [_codeLabel release];
    [_isCodeLabel release];
    [_teleLabel release];
    [_mailLabel release];
    [_mailPrint release];
    [_accountPrint release];
    [_telePrint release];
    [_codePrint release];
    [_isCodePrint release];
    
    [_accountLabel release];
    [super dealloc];
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createSubviews];
        
    }
    return self;
}

- (void)createSubviews{
    
    self.accountLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 80, 100, 40)];
    self.accountLabel.backgroundColor = [UIColor whiteColor];
    self.accountLabel.text = @"用 户 名";
    [self addSubview:_accountLabel];
    [_accountLabel release];
    
    self.codeLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 150, 100, 40)];
    self.codeLabel.backgroundColor = [UIColor whiteColor];
    self.codeLabel.text = @"密  码";
    [self addSubview:_codeLabel];
    [_codeLabel release];
    
    self.isCodeLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 220, 100, 40)];
    self.isCodeLabel.backgroundColor = [UIColor whiteColor];
    self.isCodeLabel.text = @"确认密码";
    [self addSubview:_isCodeLabel];
    [_isCodeLabel release];
    
    self.teleLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 290, 100, 40)];
    self.teleLabel.backgroundColor = [UIColor whiteColor];
    self.teleLabel.text = @"手机号";
    [self addSubview:_teleLabel];
    [_teleLabel release];
    
    self.mailLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 360, 100, 40)];
    self.mailLabel.backgroundColor = [UIColor whiteColor];
    self.mailLabel.text = @"邮  箱";
    [self addSubview:_mailLabel];
    [_mailLabel release];
    
    
    // 请输入用户名
    self.accountPrint = [[UITextField alloc] initWithFrame:CGRectMake(150, 80, 160, 35)];
    self.accountPrint.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.accountPrint];
    [self.accountPrint setBorderStyle:UITextBorderStyleRoundedRect];
    self.accountPrint.placeholder = @"请输入用户名";
    self.accountPrint.secureTextEntry = NO;
    self.accountPrint.delegate = self;
    [_accountPrint release];
    
    // 请输入密码
    self.codePrint = [[UITextField alloc] initWithFrame:CGRectMake(150, 150, 160, 35)];
    [self.codePrint setBorderStyle:UITextBorderStyleRoundedRect];
    self.codePrint.placeholder = @"请输入密码";
    self.codePrint.secureTextEntry = YES;
    [self addSubview:_codePrint];
    [_codePrint release];
    
    
    // 确认密码
    self.isCodePrint = [[UITextField alloc] initWithFrame:CGRectMake(150, 220, 160, 35)];
    [self.isCodePrint setBorderStyle:UITextBorderStyleRoundedRect];
    self.isCodePrint.placeholder = @"再次输入密码";
    self.isCodePrint.secureTextEntry = YES;
    [self addSubview:_isCodePrint];
    [_isCodeLabel release];
    
    
    // 请输入联系方式
    self.telePrint = [[UITextField alloc] initWithFrame:CGRectMake(150, 290, 160, 35)];
    [self.telePrint setBorderStyle:UITextBorderStyleRoundedRect];
    self.telePrint.placeholder = @"请输入联系方式";
    self.telePrint.secureTextEntry = NO;
    self.telePrint.keyboardType = UIKeyboardTypeNamePhonePad;
    [self addSubview:_telePrint];
    [_telePrint release];
    
    
    
    // 请输入邮箱
    self.mailPrint = [[UITextField alloc] initWithFrame:CGRectMake(150, 360, 160, 35)];
    [self.mailPrint setBorderStyle:UITextBorderStyleRoundedRect];
    self.mailPrint.placeholder = @"请输入邮箱";
    self.mailPrint.secureTextEntry = NO;
    [self addSubview:_mailPrint];
    [_mailPrint release];
    
    
    UIButton *postBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [postBtn setTitle:@"注册" forState:UIControlStateNormal];
    [postBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    postBtn.frame = CGRectMake(95, 460, 50, 50);
    [self addSubview:postBtn];
    [postBtn addTarget:self action:@selector(postBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal
     ];
    cancelBtn.frame = CGRectMake(235, 460, 50, 50);
    [self addSubview:cancelBtn];
    [cancelBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
}


- (void)textFieldDidEndEditing:(UITextField *)textField{
    self.temp = self.accountPrint.text;
    self.passwordTemp = self.codePrint.text;
}

- (void)postBtnAction:(UIButton *)btn{
    
    [self endEditing:YES];
    [[NSUserDefaults standardUserDefaults] setObject:@"yes" forKey:@"BOOL"];
    [[NSUserDefaults standardUserDefaults] setObject:self.accountPrint.text forKey:@"account"];
//    [self.myDelegate saveDataToLocation];
    [[NSUserDefaults standardUserDefaults] setObject:self.codePrint.text forKey:@"password"];
    [self.myDelegate popToUserView];
    
}

- (void)buttonAction:(UIButton *)button{
    
    
    [self.myDelegate dismissToLoginView];
}


@end
